<?php
// No direct access to this file
defined('_JEXEC') or die;
 
// import the list field type
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');
 
class JFormFieldContractor extends JFormFieldList {

	protected $type = 'Contractor';

	protected function getOptions() {
		$db = JFactory::getDBO();

		/// $query = new JDatabaseQuery; WARNING - There's an error in this line, JDatabaseQuery is an abstract class
		$query = $db->getQuery(true); // THIS IS THE FIX, WARNING IT MUST BE FIXED IN THE ZIP FILES

		$query->select('#__pricer_contractor.id as id, title AS title, #__categories.title as category, catid');
		$query->from('#__pricer_contractor');
		$query->leftJoin('#__categories on catid = #__categories.id');
		$db->setQuery((string)$query);
		$messages = $db->loadObjectList();
		$options = array();
		if ($messages) {
			foreach($messages as $message) {
				$options[] = JHtml::_('select.option', $message->id, $message->greeting .
				                      ($message->catid ? ' (' . $message->category . ')' : ''));
			}
		}
		$options = array_merge(parent::getOptions(), $options);
		return $options;
	}
}
